#!/usr/bin/env bash
# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: jaewon

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"
REPO_ROOT="$(git rev-parse --show-toplevel)"
cd "${REPO_ROOT}"

source "${SCRIPT_DIR}/py_bootstrap.sh"
cd python

BUCKET="feed.raw.coin2.corp.prestolabs.io"
USER="ec2-user"
MACHINE="$(domainname -f)"
TARGET_DATE="$(date --date='1 day ago' '+%Y%m%d')"
if [ -n "${1}" ]; then
  TARGET_DATE="${1}"
fi

echo "MACHINE='${MACHINE}'"
echo "TARGET_DATE='${TARGET_DATE}'"
echo "BUCKET='${BUCKET}'"
aws s3 cp --recursive \
  "/home/${USER}/data/flow/${MACHINE}/${TARGET_DATE}" \
  "s3://${BUCKET}/data/flow/${MACHINE}/${TARGET_DATE}/" \
  2>> "${REPO_ROOT}/log_upload_s3"
